package com.elmcode.server.controller.admin;

import com.elmcode.common.utils.R;
import com.elmcode.server.entity.BookEntity;
import com.elmcode.server.service.BookService;
import com.elmcode.server.utils.Result;
import com.elmcode.server.vo.BookDetailInfoVo;
import com.elmcode.server.vo.BookResqVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 订单
 *
 * @author laozj
 * @email laozj@elm.com
 * @date 2024-06-13 13:05:04
 */
@Api(tags = "预定接口")
@RestController
@RequestMapping("admin/book")
public class BookController {
    @Autowired
    private BookService bookService;

    /**
     * 列表
     */
    @GetMapping
    public Result list(@RequestParam Map<String, Object> params){
        BookResqVo bookVos = bookService.queryPage(params);

        return Result.ok("查询成功",bookVos.getBookVos(), bookVos.getTotal());
    }


    /**
     * 信息
     */
    @GetMapping("/{num}")
    public Result info(@PathVariable("num") String num){
		BookDetailInfoVo bookDetailInfo = bookService.getByNum(num);

        return Result.ok("订单详细信息查询成功",bookDetailInfo);
    }


    @PutMapping("/{num}/receive")
    public Result<String> receive(@PathVariable("num") String num){
        bookService.receive(num);
        return Result.ok("接单成功");
    }

    @PutMapping("/{num}/reject")
    public Result<String> reject(@PathVariable("num") String num,String reason){
        bookService.reject(num,reason);
        return Result.ok("拒单成功");
    }

    @PutMapping("/{num}/delivery")
    public Result<String> delivery(@PathVariable("num") String num){
        bookService.delivery(num);
        return Result.ok("拒单成功");
    }

    @PutMapping("/{num}/complete")
    public Result<String> complete(@PathVariable("num") String num){
        bookService.complete(num);
        return Result.ok("拒单成功");
    }



    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody BookEntity book){
		bookService.save(book);

        return R.ok();
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public R update(@RequestBody BookEntity book){
		bookService.updateById(book);

        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		bookService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
